package com.example.emailWeb.Socket.SimpleDemo;

import com.example.emailWeb.Socket.CloseUtil;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

public class ReceiveDataBuffer {
    private Socket socket;
    private DataBuffer dataBuffer;

    public ReceiveDataBuffer(Socket socket) {
        this.socket = socket;
        receivePolynomialSocketBuffer();
    }

    public DataBuffer getDataBuffer() {
        return dataBuffer;
    }

    public void receivePolynomialSocketBuffer() {
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(socket.getInputStream());
            dataBuffer = (DataBuffer) ois.readObject();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            CloseUtil.closeAll(ois, socket);
        }
    }
}
